/*
 * Copyright (C) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.kongzue.baseokhttp.util;

public class JsonMapConfig {

    private volatile static JsonMapConfig instance;


    /**
     * 预解析开关
     * <p>
     * 开启此功能将在通过 String 文本创建 JsonMap/JsonList 的一开始就对所有内容进行逐级解析，
     * 可以有效增加解析速度，例如在网络请求的异步线程先解析后返回主线程即可直接读取内部的值。
     * 但这有可能带来一些问题：
     * 例如对于文本 "objData":"{sdf123R.4:98}"，该值可能在预解析时由于 org.json 的影响，
     * 被认为是一个 JsonObject，此时若 .getString("objData")则可能返回错误的结果：
     * {"sdf123R.4":"98"}
     * 值的内容被添加了引号，这显然不符合预期。
     * 关闭预解析开关可以避免此问题，但也会带来解析过程性能的损失。
     */
    private boolean preParsing = true;

    public static JsonMapConfig getInstance() {
        if (instance == null) {
            synchronized (JsonMapConfig.class) {
                if (instance == null) {
                    instance = new JsonMapConfig();
                }
            }
        }
        return instance;
    }

    public boolean isPreParsing() {
        return preParsing;
    }

    public void setPreParsing(boolean preParsing) {
        this.preParsing = preParsing;
    }
}
